<template>
	<view class="cover-page">
		<u-loading mode="flower" color="red" size="100" class="my-loading"></u-loading>
		<view class="flex--justify">
			<text>{{tipMsg}}</text>
		</view>
	</view>
</template>

<script>
	import configdata from '@/common/config.js'
	export default {
		data() {
			return {
				// 随机请求
				baseHostUrls:[
					"hfqh170.cc",
					"hfqh169.cc",
					"hfqh168.cc"
				],
				// 固定池子 + 随机补充
				hostUrls:[
					"http://admin2.hfqh168.cc",
					"https://admin.hfqh168.cc",
				],
				// 固定请求 池
				hostUrls_v1:[
				  "https://admin1.hfqh168.cc",
				  "http://admin1.hfqh168.cc",
				  "https://admin2.hfqh168.cc",
				  "http://admin2.hfqh168.cc",
				  "https://admin.hfqh168.cc",
				  "http://admin.hfqh168.cc",
				],
				tipMsg:'正在为您优化线路....请稍后...'
			};
		},
		onLoad() {
		  this.getHostUrl_v2()
		},
		methods:{
			getHostUrl_v2: function(){
				// 生成请求路径
				for (let index in this.baseHostUrls) {
					let name = Math.random().toString(36).slice(-8);
					this.hostUrls.push("http://"+name+'.'+this.baseHostUrls[index])
					this.hostUrls.push("https://"+name+'.'+this.baseHostUrls[index])
				}
				
				// 重新配置 网络 环境
				console.log(configdata)
				async function request (hostUrl) {
				    var [error, res] = await uni.request({
				        url: hostUrl
				    });
				    if(res.data.msg != undefined && res.data.msg == 'ok'){
						let data = {
							ROOTPATH:hostUrl,
							APIHOST:hostUrl + '/index/',
							UPLOADHOST:hostUrl + '/index/index/upload'
						}
						uni.setStorageSync('web_config', JSON.stringify(data));
					}
				}
				for (let index in this.hostUrls) {
					request(this.hostUrls[index])
				}
				// 线路优化后的结果
				uni.switchTab({
					url:'../index/index'
				})
			},
			getHostUrl_v1: function(){
				// 重新配置 网络 环境
				console.log(configdata)
				async function request (hostUrl) {
				    var [error, res] = await uni.request({
				        url: hostUrl
				    });
				    if(res.data.msg != undefined && res.data.msg == 'ok'){
						let data = {
							ROOTPATH:hostUrl,
							APIHOST:hostUrl + '/index/',
							UPLOADHOST:hostUrl + '/index/index/upload'
						}
						uni.setStorageSync('web_config', JSON.stringify(data));
					}
				}
				for (let index in this.hostUrls_v1) {
					request(this.hostUrls_v1[index])
				}
				// 线路优化后的结果
				uni.switchTab({
					url:'../index/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
  .cover-page{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100%;
    background-color: #FFFFFF;
    .my-loading{
      position: absolute;
      left: 44%;
      top: 100rpx;
    }
  }
</style>
